package catalina.connection;

import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class NioChannel {

    public SocketChannel getIOChannel() {
        return sc;
    }

    public void setSc(SocketChannel sc) {
        this.sc = sc;
    }

    public NioEndPoint.NioSocketWrapper getSocketWrapper() {
        return socketWrapper;
    }

    public ByteBuffer getReadBuffer() {
        return readBuffer;
    }

    public void setReadBuffer(ByteBuffer readBuffer) {
        this.readBuffer = readBuffer;
    }

    public ByteBuffer getWriteBuffer() {
        return writeBuffer;
    }

    public void setWriteBuffer(ByteBuffer writeBuffer) {
        this.writeBuffer = writeBuffer;
    }

    public NioEndPoint.Poller getPoller() {
        return poller;
    }

    protected SocketChannel sc = null;
    protected NioEndPoint.NioSocketWrapper socketWrapper = null;

    private volatile ByteBuffer readBuffer;
    private volatile ByteBuffer writeBuffer;

    protected NioEndPoint.Poller poller;

    public NioChannel(SocketChannel channel) {
        this.sc = channel;
        this.readBuffer = ByteBuffer.allocate(1024);
    }

    // 读写缓冲数组重置
    public void reset() throws IOException {
        readBuffer.clear();
        writeBuffer.clear();
    }

    void setSocketWrapper(NioEndPoint.NioSocketWrapper socketWrapper) {
        this.socketWrapper = socketWrapper;
    }

    public void setPoller(NioEndPoint.Poller poller) {
        this.poller = poller;
    }


}
